﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Common.Utils;
using Common.Exp2D;

namespace Experiments2D.Bublz
{
    class Launcher :Object2D
    {   
        private float m_rotationSpeed = 1;

        private Vector2 m_ArrowDirection;
        public Vector2 ArrowDirection
        {
            get { return m_ArrowDirection; }
        }

        public Launcher(Texture2D arrowTexture, Vector2 position)
            : base(arrowTexture , position , true)
        {   
            m_ArrowDirection = new Vector2((float)Math.Sin(m_rotation), (float)Math.Cos(m_rotation) *-1);
        }

        public void RotateLeft(GameTime time)
        {
            if (m_rotation > (Math.PI * -1) / 3)
                m_rotation -= m_rotationSpeed * (float)time.ElapsedGameTime.TotalSeconds;

            UpdateArrowDirection();
        }

        public void SetAngle(float angle)
        {
            m_rotation = angle;
            UpdateArrowDirection();
        }

        public void RotateRigth(GameTime time)
        {
            if (m_rotation < Math.PI / 3)
                m_rotation += m_rotationSpeed * (float)time.ElapsedGameTime.TotalSeconds;

            UpdateArrowDirection();
        }

        private void UpdateArrowDirection()
        {
            m_ArrowDirection.X = (float)Math.Sin(m_rotation);
            m_ArrowDirection.Y = (float)Math.Cos(m_rotation) * -1;

            //m_ArrowDirection.Normalize();

            
        }

        

        //public override void Draw(GameTime time, SpriteBatch spriteBatch)
        //{            
        //    base.Draw(time, spriteBatch);            
        //}

    }
}
